package ec.atreasure.com.atreasureecandroid;

import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;

import ec.atreasure.com.core.activity.AtreasureActivity;
import ec.atreasure.com.core.app.AccountManager;
import ec.atreasure.com.core.app.Atreasure;
import ec.atreasure.com.core.app.IUserChecker;
import ec.atreasure.com.core.fragments.AtreasureFragment;
import ec.atreasure.com.ec.launcher.LauncherFragment;
import ec.atreasure.com.ec.launcher.LauncherScrollFragment;
import ec.atreasure.com.ec.login.ILoginListener;
import ec.atreasure.com.ec.login.IRegisterListener;

public class MainActivity extends AtreasureActivity implements
        ILoginListener, IRegisterListener{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null)
            actionBar.hide();

        Atreasure.getConfigurator().withActivity(this);
    }

    @Override
    public AtreasureFragment setRootFragment() {

        final AtreasureFragment[] atreasureFragment = new AtreasureFragment[1];

        AccountManager.checkAccount(new IUserChecker() {
            @Override
            public void onLoginIn() {
                //已登录用户跳转界面
                atreasureFragment[0] = new LauncherFragment();
            }

            @Override
            public void onNotLoginIn() {
                //未登录用户跳转界面
                atreasureFragment[0] = new LauncherScrollFragment();
            }
        });

        return atreasureFragment[0];

//        return new MainFragment();
//        return new LauncherScrollFragment();
//        return new LoginFragment();
//        return new RegisterFragment();
    }

    @Override
    public void onLoginInSuccess() {
        Toast.makeText(this, "登录成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onRegisterSuccess() {
        Toast.makeText(this, "注册成功", Toast.LENGTH_LONG).show();
    }

}
